package com.puccampinas.finalproject.rest;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import com.eaio.uuid.UUID;
import com.puccampinas.finalproject.core.logs.LogUtils;
import com.puccampinas.finalproject.core.logs.LoggerType;
import com.puccampinas.finalproject.rest.to.RequestResponse;
import com.puccampinas.finalproject.rest.to.ResponseStatus;

@Path("/api")
public class RequestHandler {

	@GET
    @Path("ping")
    @Produces({MediaType.APPLICATION_XML})
    public RequestResponse ping(@Context HttpServletRequest request) {

    	LogUtils.info(LoggerType.REQUESTS_ANSWERED, "Requested. | URL=" + request.getRequestURL() + (request.getQueryString() == null ? "" : "?" + request.getQueryString()));
    	
        String ticket = new UUID().toString();

        RequestResponse requestResponse = new RequestResponse();

        requestResponse.setDate(new Date());
        requestResponse.setTicket(ticket);
        requestResponse.setStatus(ResponseStatus.OK);

        LogUtils.info(LoggerType.REQUESTS_ANSWERED, "Answered. | URL=" + request.getRequestURL() + (request.getQueryString() == null ? "" : "?" + request.getQueryString()) + " | ANSWER=" + requestResponse.toString());
        
        return requestResponse;
    }

}
